<?php

namespace app\model;

use think\Model;

class StationOperation extends Model
{
    public function insertData(): array
    {
        $param = request()->post();
        $param['content'] = htmlspecialchars($param['content'] ?? '');
        $this->exists(!empty($param['id']))->save($param);
        return $this->toArray();
    }

    public function pageData(): array
    {
        $param = request()->param();
        $data = $this->when(!empty($param['name']),function ($query) use ($param){
            $query->where('name','like',"%{$param['name']}%");
        })->order('create_time','desc')->paginate(['list_rows' => 30,'page' => $param['page'] ?? 1])->toArray();
        return pageData($data);
    }
}
